
package cs2114.antiFingerMines;

// -------------------------------------------------------------------------
/**
 *  This class is part of the four other classes that utilizes threads
 *  to make the app run faster.
 *
 *  @author William-Laptop
 *  @version Apr 20, 2012
 */
public class MineDistanceFiveb extends Thread
{

	Location finger;
	Mine[] field;
	float closest;

	// ----------------------------------------------------------
    /**
     * Create a new MineDistanceOne object.
     * @param loc the fingers current location
     * @param mines the field of mines
     */
	public MineDistanceFiveb(Location loc, Mine[] mines)
	{
		finger = loc;
		field = mines;
		closest = 99999;
	}

	 /**
     * This thread only runs on the first fifth of the mine field and also
     * sets the smallest distance between the finger and the mine to closest
     */
	public void run()
	{
		for (int i = 4*field.length/5; i < field.length; i++)
        {
            if (field[i].traversableDistanceBetween(finger) <= closest)
            {
                closest = field[i].traversableDistanceBetween(finger);
            }
        }
	}

	 /**
     * This method returns closest so that it can be compared to the closest
     * values returned from the other threads.
     * @return float is the closest mine to the finger in the first fifth
     * of the minefield
     */

	public float getClosest()
	{
		return closest;
	}

}
